{% extends "student/base.html" %}
{% block content %}
<head>
    <meta charset="UTF-8">
    <title>show_classes</title>
    <link rel="stylesheet" href="{{ STATIC_URL }}common.css">
</head>
<body>
    <table class="gridtable" align="center">
        <tbody>
            <tr>
                <th colspan="5" align="center">课程列表</th>
                <!-- <th colspan="4"  align="center"><a href="/student/add_grade/">添加课程信息</a></th> -->
            </tr>
            <tr>
                <th align="center">CourseID</th>
                <th align="center">课程名称</th>
                <th colspan="2" align="center">操作</th>
                <th align="center">课程评分</th>
            </tr> 
            {% for course in course_list %}  
            <tr id="course"></tr>
                <td>{{ course.courseid}}</td>
                <td>{{ course.coursename }}</td>
                <td>
                <button type="submit" id="select_button" class="btn btn-default">旁听</button>
                </td>
                <td><a href="{{SITE_URL}}student/show_comment/?courseid={{ course.courseid }}">评论区</a></td>
                <td>{{ course.grades }}</td>
            </tr>  
            {% endfor %}                   
        </tbody>
    </table>
</body>

<script>
    function select_course(courseid,coursename) {
        $.ajax({
            type: "get",
            url: "{{SITE_URL}}student/selectcourse/",
            data: {
             "courseid" : courseid,
             "coursename" : coursename,
            },
            success:function (response) {
                alert(response['message'])
            }
        })
    }
    $(":submit").click(function (){
        courseid = $(this).parent().siblings('td')[0].innerHTML
        coursename = $(this).parent().siblings('td')[1].innerHTML
        $(this).text("已旁听")
        select_course(courseid,coursename)
    })
</script>
{% endblock %}